//
//  WelcomsView.swift
//  WSWB
//
//  Created by 刘 伟生 on 16/1/13.
//  Copyright © 2016年 seasa. All rights reserved.
//

import UIKit

class WelcomsView: UIViewController {

   
    @IBOutlet weak var iconViwe: UIImageView!
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        
        iconViewAnimation()
        
    }
    
    //动画函数
    func iconViewAnimation() {
        
        //首先动态计算出图片移动的的距离
        //假设移动到的位置的y值为160
        iconViwe.alpha = 0.5
        let offsetY = UIScreen.mainScreen().bounds.size.height - iconViwe.frame.size.height - 260
        
        UIView .animateWithDuration(2.0, animations: { () -> Void in
            
            self.iconViwe.transform = CGAffineTransformMakeTranslation(0, -offsetY)
            self.iconViwe.alpha = 0.5
            
            
            }) { (isFinish) -> Void in
                //在这里来跳转到主页上面
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW,  (Int64)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), { () -> Void in
                    
                    //先获取当前的窗口
//                    let window = UIApplication.sharedApplication().keyWindow
//                    
//                    let storyBoard = UIStoryboard(name: "Main", bundle: nil)
//                    let TabVC = storyBoard.instantiateInitialViewController()
//                    
//                    //将控制器设置为跟控制器
//                    window?.rootViewController = TabVC
                    
                    //使用通知,通知Appdelegate进行跳转
                    NSNotificationCenter.defaultCenter().postNotificationName(XMGChangeRootViewControllerNotification, object: nil, userInfo: ["message" : true])
                    
                })
               
        }
    }

}
